﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CaiyinSoft.NetGather.Protocol;

namespace CaiyinSoft.NetGather.NetGatherLib.Filter.Process
{
    [Serializable]
    public class HTMLInnetTextHTMLAnalyze : HTMLFilterBase
    {


        public override string FilterCaption
        {
            get
            {
                return "内文本过滤器";
            }
        }

        public override string ExpressionCaption
        {
            get
            {
                return "";
            }
        }

        public override string Description
        {
            get
            {
                return "获取元素InnerText";
            }
        }

        //public int ProcessType { get; private set; }

        public HTMLInnetTextHTMLAnalyze():base()
        {
            _InitParams();
        }

        private void _InitParams()
        {
            SetInputHTML("");
            OutputKey = Guid.NewGuid().ToString();
            //OutputType = 0;
            //ProcessType = 3;
        }

        public override List<FilterResult> FilterHTML()
        {
            int parentHTMLPosition = 0;
            if (ParentFilter != null)
                parentHTMLPosition = ParentFilter.HTMLPosition;
            HTMLPosition = parentHTMLPosition;

            List<FilterResult> parentResults = GetInputHTML();
            if (parentResults == null || parentResults.Count == 0) return null;
            List<FilterResult> listRevalue = new List<FilterResult>();

            foreach (var pr in parentResults)
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(pr.HTMLResult);
                FilterResult result = new FilterResult(pr.HTMLPosition, doc.DocumentNode.InnerText);
                listRevalue.Add(result);
            }
            return listRevalue; // 

            //HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            //doc.LoadHtml(GetInputHTML());
            //return doc.DocumentNode.InnerText;
        }

    }
}
